package com.chzker.action;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.chzker.model.Wishes;
import com.chzker.service.WishesManager;
import com.chzker.util.PageControl;
  
@Component("wishesAction")
@Scope("prototype")   
public class WishesAction extends BaseAction {  
  
	private Log log = LogFactory.getLog(WishesAction.class);
    private WishesManager wishesManager;
    private Integer wish_id;
    private String wish_owner;
    private String wish_ownerstate;
    private String wish_content;
    private Date wish_date;
    private List wishes;
    private Integer num;

//==============================填写祝福======================================//    
    public String add(){
    	try{
			if (!wish_owner.equals("")&&!wish_content.equals("")) {
				Wishes wish = new Wishes();
				wish.setWishOwner(wish_owner);
				wish.setWishContent(wish_content);
				wish.setWishOwnerstate(wish_ownerstate);
				// SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd");
				// String date = new Date().toString();
				// date=dateFm.format(wish_date);
				wish.setWishDate(new Date());
				wish.setWishState(0);
				//log.info("=====*****" + wish_owner+"===="+ wish_content + wish_ownerstate);
				String result = wishesManager.add(wish);
				return result;
    		}else{
    			return "addFalse";
    		}
    	}catch(Exception e){
    		e.printStackTrace();
    		return "addFalse";
    	}    	
    }
    
//============================根据ID删除留言祝福================================//
    public String delById(){
    	String result=this.wishesManager.delById(wish_id);
    	this.setPage(getPage());
		this.setPageSize(getPageSize());
    	return result;
    }
    
//============================根据ID审核通过留言祝福================================//
    public String passById(){
    	String result=this.wishesManager.passWishById(wish_id);
    	return result;
    }

//==============================查询指定行数==================================//
    public String listWishesByNum(){  
    	try{
    		wishes = this.wishesManager.listPassWishesByNum(num);
            return "listWishes";  
    	}catch(Exception e){
    		e.printStackTrace();
    		return "error";
    	}
    	
    }
    
    /******************************分页展示数据*******************************/	
	public String listWishesByPage(){  
		try{
			//log.info("================"+getPage()+"=========="+getPageSize());
			PageControl pc =new PageControl();
			pc.setPage(getPage());
			pc.setPageSize(getPageSize());
			wishes = this.wishesManager.listWishesInPage(pc);
			this.setPage(pc.getPage());
			this.setPageSize(pc.getPageSize());
			this.setPrePage(pc.getPrePage());
			this.setNextPage(pc.getNextPage());
			this.setEndPage(pc.getEndPage());
			return "listWishesBack";
		}catch(Exception e){
			e.printStackTrace();
			return "error";
		} 
    }
	
    /******************************后台分页展示数据*******************************/	
	public String listUnpassWishesByPageBack(){  
		try{
			//log.info("================"+getPage()+"=========="+getPageSize());
			PageControl pc =new PageControl();
			pc.setPage(getPage());
			pc.setPageSize(getPageSize());
			wishes = this.wishesManager.listUnpassWishesInPageBack(pc);
			this.setPage(pc.getPage());
			this.setPageSize(pc.getPageSize());
			this.setPrePage(pc.getPrePage());
			this.setNextPage(pc.getNextPage());
			this.setEndPage(pc.getEndPage());
			return "listUnpassWishesBack";
		}catch(Exception e){
			e.printStackTrace();
			return "error";
		} 
    }
    
//==============================默认执行方法==================================//
    public String execute() throws Exception {  
    	try{
			//log.info("================"+getPage()+"=========="+getPageSize());
			PageControl pc =new PageControl();
			pc.setPage(getPage());
			pc.setPageSize(getPageSize());
			wishes = this.wishesManager.listWishesInPage(pc);
			this.setPage(pc.getPage());
			this.setPageSize(pc.getPageSize());
			this.setPrePage(pc.getPrePage());
			this.setNextPage(pc.getNextPage());
			this.setEndPage(pc.getEndPage());
			return "listWishes";
		}catch(Exception e){
			e.printStackTrace();
			return "error";
		} 
    }
    
    
//=========================Setter And Getters==================================//   
	public WishesManager getWishesManager() {
		return wishesManager;
	}
	@Resource
	public void setWishesManager(WishesManager wishesManager) {
		this.wishesManager = wishesManager;
	}
	public String getWish_owner() {
		return wish_owner;
	}
	public void setWish_owner(String wishOwner) {
		wish_owner = wishOwner;
	}
	public String getWish_ownerstate() {
		return wish_ownerstate;
	}

	public void setWish_ownerstate(String wish_ownerstate) {
		this.wish_ownerstate = wish_ownerstate;
	}

	public String getWish_content() {
		return wish_content;
	}
	public void setWish_content(String wishContent) {
		wish_content = wishContent;
	}
	public Date getWish_date() {
		return wish_date;
	}
	public void setWish_date(Date wishDate) {
		wish_date = wishDate;
	}

	public Integer getWish_id() {
		return wish_id;
	}

	public void setWish_id(Integer wishId) {
		wish_id = wishId;
	}

	public List getWishes() {
		return wishes;
	}

	public void setWishes(List wishes) {
		this.wishes = wishes;
	}

	public Integer getNum() {
		return num;
	}

	public void setNum(Integer num) {
		this.num = num;
	}  
    
} 
